package controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import model.Employee;
import model.Envelope;
import view.CustomerHistoryGui;
import view.GetCustomerListGui;
import view.SalesManGui;
/**
 * main menu for sales men
 * @author liran 
 *
 */
public class SalesManControllers extends AbstractTransfer{
	/**
	 * the gui
	 */
	private SalesManGui saleGui = null; 
	/**
	 * for back - logout 
	 */
	private LoginController backC = null; 
	/**
	 * the employee details
	 */
	private Employee EmpM = null;
	private SalesManControllers tempCon = null;

	/**
	 * constructor 
	 * @param l->LoginController
	 * @param e->Employee
	 * @param g->SalesManGui
	 */
	public SalesManControllers(LoginController l,Employee e,SalesManGui g){
		super(g,e);
		backC = l;
		EmpM = e;
		tempCon = this;
		saleGui = g;
		System.out.println("asdas");
		saleGui.addLogOutAL(new LogOutListen());
		saleGui.addGetCustListAL(new GetCustlistlisten());
		saleGui.addCustomerHistoryAL(new CustomerHisListen());
	}
	/**
	 * log out 
	 * @author liran
	 *
	 */
	class LogOutListen implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			UpdateDB();
			saleGui.dispose();
			backC.getLoginG().ClearText();
			backC.getLoginG().setVisible(true);
		}
	}

	class GetCustlistlisten implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			
			saleGui.dispose();
		    GetCustomerListGui lisgui = new GetCustomerListGui();
			GetCustomerListConntroler liscon = new GetCustomerListConntroler(tempCon, lisgui,EmpM, backC);
			
			
		}
	}
	class CustomerHisListen implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			saleGui.dispose();
			CustomerHistoryGui HisGui = new CustomerHistoryGui();
			CustomerHistoryController HisCon = new CustomerHistoryController(tempCon, HisGui, EmpM );
		}
	}
	
	public void UpdateDB(){
		 Envelope en1 = new Envelope(EmpM,"updateStatus0");
		 sendToServer(en1);
	} 
	
	public SalesManGui GetSalesManGui()
	{
		return saleGui;
	}
	
	
	
}
